<?php

class item_m_cart extends a_base_model_datamapper implements i_return_product_l_cart{

    public function __construct($id=null) {
        $this->table = 'cart_items';
        $this->has_many = array(
        );
        $this->has_one = array(
        );

        $this->has_one['cart_m_cart'] = array(
            'class' => 'cart_m_cart',
            'join_other_as' => 'cart',
            'join_self_as' => 'item'
        );
        parent::__construct($id);
    }

    public function get_product(){
        $prod = new product_m_product();
        $prod->get_by_id($this->product_id);
        if($prod->exists()){
            return $prod;
        }else{
            return NULL;
        }
    }

    public function price_x_qty(){
        return round($this->get_product()->get_price() * $this->qty ,2 );
    }
}
?>